<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@include file="/WEB-INF/commons/taglibs.jsp"%>
<%@include file="/WEB-INF/commons/common-header.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
$(function() {
	var currentUrl = document.URL;
	if (currentUrl && currentUrl.indexOf("edit") !== -1) {
		$("#username").attr("readonly", "readonly");
	} else {
		$("#username")
				.blur(
						function() {
							var input_value = $.trim($("#username").val());
							$
									.ajax({
										url : "${ctx}/checkRegistUser",
										type : "POST",
										data : {
											 "_method" : "POST", 
											"username" : input_value
										},
										dataType : "json",
										success : function(data) {
											backstring = data.state;
											if (data
													&& backstring
													&& (backstring
															.indexOf("ERROR") != -1)) {
												alert(data.message);
												return;
											} else if (backstring == "USEREXIST") {
												$("#username")
														.focus()
														.parent("td")
														.siblings(
																".s_addutTips")
														.html(
																"<p style='color:red;'>该用户名已经申请</p>");
												$("input[type='submit']")
														.attr("disabled",
																true);
											} else {
												$("#username")
														.parent("td")
														.siblings(
																".s_addutTips")
														.empty();
												$("input[type='submit']")
														.attr("disabled",
																false);
											}
										}
									});
						});
	}
});
</script>
</head>
<body>
	<form:form method="post" modelAttribute="user" id="form">
		<input type="hidden" name="_method" value="${_method }" />
		<!--content start-->
		<ul class="s_bodyR">
			<li class="s_li_head">用户管理&gt;用户编辑</li>
			<li class="s_adduTable">
				<table width="800" border="0">
					<tr>
						<td width="176" class="s_addutName">用户名称：</td>
						<td width="289"><form:input path="username" id="username" class="s_tInput" /></td>
						<td width="321" class="s_addutTips"></td>
					</tr>
					<tr>
						<td class="s_addutName">用户密码：</td>
						<td><form:password path="password"  id="password"  showPassword="true" class="s_tInput" /></td>
						<td class="s_addutTips"></td>
					</tr>
					<tr>
						<td class="s_addutName">用户姓名：</td>
						<td><form:input path="name" id="name" type="text" class="s_tInput" /></td>
						<td class="s_addutTips"></td>
					</tr>
					<tr>
						<td class="s_addutName">用户邮件：</td>
						<td><form:input path="email" id="email"
								type="text"  class="s_tInput" /></td>
						<td class="s_addutTips"></td>
					</tr>
					<tr>
						<td class="s_addutName">用户QQ：</td>
						<td><form:input path="qq" id="qq"
								type="text" class="s_tInput" /></td>
						<td class="s_addutTips"></td>
					</tr>
					<tr>
						<td class="s_addutName">用户手机：</td>
						<td><form:input path="mobilePhone" id="mobilePhone" class="s_tInput" /></td>
						<td class="s_addutTips"></td>
					</tr>
					<shiro:hasPermission name="security:manage">
					<tr>
						<td class="s_addutName">用户角色：</td>
						<td><c:forEach var="role"
								items="${roles }">
								<c:choose>
									<c:when test="${user.rolesTrans[role.id] ne null }">
										<input type="checkbox" id="role${role.id }"
											name="rolesTrans[${role.id }]" value="${role.id}"
											checked="checked" />
										<label for="role${role.id }">${role.showName }</label>
									</c:when>
									<c:otherwise>
										<input type="checkbox" id="role${role.id }"
											name="rolesTrans[${role.id }]" value="${role.id}" />
										<label for="role${role.id }">${role.showName }</label>
									</c:otherwise>
								</c:choose>
							</c:forEach></td>
						<td class="s_addutTips"></td>
					</tr>
					</shiro:hasPermission>
					<tr>
						<td></td>
						<td><p class="s_brpLeft">
								<input id="ok" type="submit" value="提交" class="s_submit" />&nbsp;
								<button id=“back” class="s_button"
									onclick="javascript:history.go(-1);">返回</button>
							</p></td>
						<td></td>
					</tr>
				</table>
			</li>
		</ul>
		<!--content end-->
	</form:form>
</body>
</html>